#!/bin/sh -xe

npm install --no-fund --no-audit --unsafe-perm --allow-root -registry=https://registry.npmmirror.com/ -@qtrade:registry=https://f2e.qtrade.com.cn/verdaccio/
# npm install --no-fund --no-audit --unsafe-perm --allow-root --no-package-lock -registry=https://registry.npmmirror.com/ -@qtrade:registry=https://f2e.qtrade.com.cn/verdaccio/
sed -i 's/?cache=0.*tgz//g' package-lock.json
sed -i 's/registry.nlark.com/f2e.qtrade.com.cn\/verdaccio/g' package-lock.json
sed -i 's/registry.npm.taobao.org/f2e.qtrade.com.cn\/verdaccio/g' package-lock.json
sed -i 's/registry.npmmirror.com/f2e.qtrade.com.cn\/verdaccio/g' package-lock.json
sed -i 's/registry.npmjs.org/f2e.qtrade.com.cn\/verdaccio/g' package-lock.json

# qidian 项目有 submodule
if [ $CI_PROJECT_NAME = "qidian" ]; then
  cd ./qtrade-ui
  npm install --no-fund --no-audit --unsafe-perm --allow-root -registry=https://registry.npmmirror.com/ -@qtrade:registry=https://f2e.qtrade.com.cn/verdaccio/
  # npm install --no-fund --no-audit --unsafe-perm --allow-root --no-package-lock -registry=https://registry.npmmirror.com/ -@qtrade:registry=https://f2e.qtrade.com.cn/verdaccio/
  sed -i 's/?cache=0.*tgz//g' package-lock.json
  sed -i 's/registry.nlark.com/f2e.qtrade.com.cn\/verdaccio/g' package-lock.json
  sed -i 's/registry.npm.taobao.org/f2e.qtrade.com.cn\/verdaccio/g' package-lock.json
  sed -i 's/registry.npmmirror.com/f2e.qtrade.com.cn\/verdaccio/g' package-lock.json
  sed -i 's/registry.npmjs.org/f2e.qtrade.com.cn\/verdaccio/g' package-lock.json
  cd ../
fi